import http from '../../utils/http'
export const SAVE_ARTICLE = 'article/SAVE_ARTICLE'

/**
 * 获取文章新闻推荐
 * @param {*} channel_id 频道ID
 * @param {*} timestamp  时间戳，请求新的推荐数据传当前的时间戳，请求历史推荐传指定的时间戳
 * @returns Promise<Action>
 */
export const getArticles = ({ channel_id = 0, timestamp = Date.now() }) => {
  return async (dispatch) => {
    const res = await http.get(`/v1_0/articles`, { params: { channel_id, timestamp } })
    console.log(`/v1_0/articles`, res)
    // dispatch 一个 action 给 reducer
    dispatch({ type: SAVE_ARTICLE, payload: res.data.results })
  }
}
